package hotel.meituan.oversea.biz.controller;

import com.alibaba.fastjson.JSON;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.utils.Result;
import hotel.base.oversea.vo.meituan.MtHotelOrderJobDealVo;
import hotel.base.oversea.vo.meituan.request.order.MtHotelOrderCheckParamVo;
import hotel.meituan.oversea.biz.service.MtHotelOrderDealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 美团酒店订单处理Controller
 * @author qiuyy
 * @date 2020-09-14
 */
@Slf4j
@RestController
@RequestMapping("/mtHotelOrderDeal")
@Api(value = "MtHotelOrderDealController", tags = {"美团酒店订单处理接口"})
public class MtHotelOrderDealController {
    @Autowired
    private MtHotelOrderDealService mtHotelOrderDealService;


    /**
     *
     * 定时器处理美团订单
     *
     * （取消订单由通知单方法处理）
     *
     * @return
     */
    @PostMapping("/jobNewOrderBooking")
    @ApiOperation(value = "定时器处理美团订单",notes="必须经过auth授权")
    public Result<Object> jobNewOrderBooking(@RequestBody MtHotelOrderJobDealVo mtHotelOrderJobDealVo){
        log.info("jobNewOrderBooking定时器处理美团订={}", JSON.toJSONString(mtHotelOrderJobDealVo));
        if(null == mtHotelOrderJobDealVo.getSwPoolId()){
            return new Result<>("SwPoolId 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getSwOrderId()){
            return new Result<>("SwOrderId 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getSwHotelId()){
            return new Result<>("SwHotelId 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getSwRoomId()){
            return new Result<>("SwRoomId 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getMtHotelId()){
            return new Result<>("MtHotelId 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getGoodsId()){
            return new Result<>("GoodsId 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getCheckinDate()){
            return new Result<>("CheckinDate 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getCheckoutDate()){
            return new Result<>("CheckoutDate 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getRoomnum()){
            return new Result<>("Roomnum 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getTotalPrice()){
            return new Result<>("TotalPrice 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getContactName()){
            return new Result<>("ContactName 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getPersonNames()){
            return new Result<>("PersonNames 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderJobDealVo.getContactPhone()){
            return new Result<>("ContactPhone 不可为空", CommonConstants.REQUEST_ERROR);
        }
        Result result = mtHotelOrderDealService.jobNewOrderBooking(mtHotelOrderJobDealVo);
        log.info("jobNewOrderBooking定时器处理美团订result={}", JSON.toJSONString(result));
        return result;
    }
    /**
     *
     * 公共校验方法
     *
     * @return
     */
    @PostMapping("/checkOrderPrice")
    @ApiOperation(value = "公共校验方法校验携程订单价格是否可接单",notes="必须经过auth授权")
    public Result<Object> checkPriceUpDown(@RequestBody MtHotelOrderCheckParamVo mtHotelOrderCheckParamVo){
        log.info("公共校验方法校验携程订单价格是否可接单={}", JSON.toJSONString(mtHotelOrderCheckParamVo));
        if(null == mtHotelOrderCheckParamVo){
            return new Result<>("mtHotelOrderCheckParamVo 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderCheckParamVo.getHotelId()){
            return new Result<>("HotelId 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderCheckParamVo.getGoodsId()){
            return new Result<>("GoodsId 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderCheckParamVo.getCheckinDate()){
            return new Result<>("CheckinDate 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderCheckParamVo.getCheckoutDate()){
            return new Result<>("CheckoutDate 不可为空", CommonConstants.REQUEST_ERROR);
        }
        if(null == mtHotelOrderCheckParamVo.getTotalPrice()){
            return new Result<>("TotalPrice 不可为空", CommonConstants.REQUEST_ERROR);
        }
        return mtHotelOrderDealService.checkPriceUpDownCommon(mtHotelOrderCheckParamVo);
    }

}
